package com.spzx.order.controller;


import com.spzx.common.core.context.SecurityContextHolder;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.order.domain.OrderForm;
import com.spzx.order.domain.OrderInfo;
import com.spzx.order.domain.TradeVo;
import com.spzx.order.service.OrderInfoService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/orderInfo")
@RestController
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @GetMapping("/trade")
    public AjaxResult trade() {
        Long userId = SecurityContextHolder.getUserId();
        TradeVo tradeVo = orderInfoService.trade(userId);
        return AjaxResult.success(tradeVo);
    }

    @PostMapping("/submitOrder")
    public AjaxResult submitOrder(@RequestBody OrderForm orderForm){

        Long l =  orderInfoService.submitOrder(orderForm);
        return AjaxResult.success(l);
    }

    @GetMapping("/getOrderInfo/{orderId}")
    public AjaxResult getOrderInfo(@PathVariable("orderId") Long orderId){
        OrderInfo orderInfo = orderInfoService.getOrderInfo(orderId);
        return AjaxResult.success(orderInfo);
    }

}
